#ifndef CPARSER_H
#define CPARSER_H

#include "Link.h"
#include "CPanel.h"

extern "C"
{
	#include "cho.h"
}

class CParser
{
	public:
		CParser();			//constructor
		~CParser();			//deconstructor

		void Start(char **cmd, int size);	//start program
		void Start(double lg, double *es, double *em);	//for DEBUG

		void Input(char *infile);			//input file from txt

		void OutputImage() const;			//output image information for OPENGL
		void OutputFileForFastCap();		//output panel for fastcap
		void Output(char *filename);

	private:
		void Refine(const int i, const int j, const double *err);	//refinement for dividing panels
		void RefineScheme();	//refine for root panels
		void BuildP();																	//build P matrix
		void SolveCho();																//solve P matrix by cholesky decomposition

		void AddCLink(const unsigned int, const unsigned int);							//add potential link
		void insertP(double value, unsigned int i, unsigned int j, bool flag = true);	//insert elements for P matrix
		double GetPotential(const unsigned int i, const unsigned int j);				//get potential value

		void Command(char **cmd, int size);	//command line
		void Help() const;					//print out help manual

	private:
		unsigned int condNum;				//the number of conductor number
		unsigned int InputpanelNum;			//the number of input panels 
		unsigned int panelNum;				//the number of total panels
		int basisNum;						//basis number
		double Lguard;						//length guard
		double *errM;						//error estimation for mutual capacitance
		double *errS;						//error estimation for self-capacitance
		double *C;							//for capacitnce matrix

		vector<CPanel*> panelptr;			//panels in vector
		vector<CLink*> clinkptr;			//the parameters which can build P matrix
		vector<unsigned int> *LeafVector;	//a vector to record leaf panels
		vector<unsigned int> *condVector;	//a vector to record conductor index
		vector<PLink*> plinkptr;			//potential of p matrix
		vector<PLink*> buff;				//buffer to plinkptr
};

#endif
